package com.jgk.guice.basic.gettingstarted;

import java.util.Properties;

import org.springframework.context.ApplicationContext;

import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
import com.google.inject.spring.SpringIntegration;

public class BillingModule extends AbstractModule {
    private final Properties myProperties;
    private ApplicationContext applicationContext;
    public BillingModule(ApplicationContext applicationContext) {
        this.myProperties = new Properties();
        myProperties.put("greeting","hello");
        myProperties.put("goodbye","later");
        myProperties.put("last name","kroubalkian");
        this.applicationContext = applicationContext;
    }
    @Override
    protected void configure() {
        if(applicationContext!=null) {
            System.out.println("WRAPPING APP CONTEXT");
            SpringIntegration.bindAll(binder(),applicationContext);
        }
        /*
         * 
         * This tells Guice that whenever it sees a dependency on a
         * TransactionLog, it should satisfy the dependency using a
         * DatabaseTransactionLog.
         */
        bind(TransactionLog.class).to(DatabaseTransactionLog.class);
        
        bind(DatabaseTransactionLog.class).to(MySqlDatabaseTransactionLog.class);

        /*
         * Similarly, this binding tells Guice that when CreditCardProcessor is
         * used in a dependency, that should be satisfied with a
         * PaypalCreditCardProcessor.
         */
        bind(CreditCardProcessor.class).to(PaypalCreditCardProcessor.class);
        
        bind(String.class)
        .annotatedWith(Names.named("FREAKY API key"))
        .toInstance("this is one FREEEEEEEAKY API KEY");
        
        Names.bindProperties(this.binder(), myProperties);
    }

}
